﻿@model int
@{
    var page = (Kooboo.CMS.Sites.Models.Page)ViewContext.Controller.ViewData.Model;

    IEnumerable<Kooboo.CMS.Sites.Models.Page> pages = null;
    if (page.Parent == null)
    {
        pages = ServiceFactory.PageManager.All(page.Site, "");
    }
    else
    {
        pages = ServiceFactory.PageManager.All(page.Site, page.Parent.FullName, "");
    }
}
<tr id="sortPagesTr">
    <td></td>
    <td>
        <input type="hidden" name="@ViewData.TemplateInfo.HtmlFieldPrefix" value="@Model" />
        <input name="PageOrders" type="hidden" />
        <h5 class="sortpages-header">@("Menu order".Localize())<em class="tip">@("The order of page in the menu API. Drag and drop to change them.".Localize())</em></h5>
        <ul class="sortpages">
            @foreach (var item in pages)
            {
                <li data-pagename="@item.FullName" class='@(item.FullName == page.FullName ? "current" : "")'>
                    <img src="/Images/invis.gif" class="icon drag">@item.LinkText</li>
            }
            @if (string.IsNullOrEmpty(page.Name))
            {
                <li data-pagename="!NEWPAGE!" class="current">
                    <img src="/Images/invis.gif" class="icon drag">@("This new page".Localize())</li>
            }
        </ul>
        <script>
            $(function () {
                $(".sortpages").sortable({
                    update: function (event, ui) {
                        var pageNameOrders = "";
                        _.each($('[data-pagename]').toArray(), function (item, index) {
                            pageNameOrders = pageNameOrders + "|" + $(item).data('pagename');
                        });
                        $('[name=PageOrders]').val(pageNameOrders);
                    }
                });
                $(".sortable").disableSelection();

                $('#Navigation_Show').change(function () {
                    if ($(this).attr('checked') == 'checked') {
                        $('#sortPagesTr').show();
                    }
                    else {
                        $('#sortPagesTr').hide();
                    }
                });

                $('#Navigation_Show').trigger('change');
            });
        </script>
    </td>
</tr>
